<?php

class ScrapyOpen extends OpenBase
{

	private $api = null;

	public function __construct()
	{
		$this->api = n_api('scrapy');
	}

	// public function generateTaskLists()
	// {
	// 	$param = $this->param('
	// 		clientIp:char:empty
	// 	');
	// 	$clientIp = ip2long($param['clientIp']);
	// 	$apiReturn = $this->api->getAllTasks($clientIp);

	// 	echo json_encode($apiReturn);
	// }

	/**
	 * 提供爬取端访问的url地址
	 * @return void
	 */
	// public function generateTaskUrls()
	// {
	// 	$param = $this->param('
	// 		taskId:char:empty
	// 	');
	// 	$taskId = $param['taskId'];

	// 	$rs = $this->api->getTaskDetail($taskId);

	// 	echo json_encode($rs);
	// }

	// public function heartBeat()
	// {
	// 	$param = $this->param('
	// 		taskId:char:empty,
	// 		clientIp:char:empty
	// 	');

	// 	$this->api->heartbeatToMongo($param);
	// 	echo "true";
	// }

	// public function rollbackTaskUrl()
	// {
	// 	$param = $this->param('
	// 		taskId:char:empty,
	// 		taskUrl:char:empty
	// 	');

	// 	n_logSave("rollback.log", var_export($param, true));

	// 	$taskId = $param['taskId'];
	// 	$urls = json_decode($param['taskUrl'], true);
	// 	if ($urls == NULL){
	// 		$url = $param['taskUrl'];
	// 		$this->api->pushTaskList($taskId, $url);
	// 	}
	// 	else{
	// 		foreach ($urls as $url) {
	// 			$this->api->pushTaskList($taskId, $url);
	// 		}
	// 	}

	// 	echo "true";
	// }

	public function rollbackCookie()
	{
		$param = $this->param('
			taskName:char:empty,
			taskCookie:char:empty
		');
		
		$taskName = $param['taskName'];
		$taskCookie = stripslashes($param['taskCookie']);
		$this->api->addCookie($taskName, $taskCookie);
		echo "fuckyou";
	}
}